package com.colorlight.cloud.complete.entity.enumerate;

import com.colorlight.cloud.common.exception.ParameterException;
import com.colorlight.cloud.common.model.ExceptionEnum;
import com.colorlight.cloud.gateway.api.message.constraint.basics.ienum.EnumTrans;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * @author Demon
 * @description TODO
 * @date 14/12/2023 下午4:18
 */
@Getter
public enum RealTimeMode implements EnumTrans<Integer, RealTimeMode> {
  /** 1是指定日期模式，2是指定周期模式 DATE_EXECUTION 只能有1个limitDate PERIODIC_EXECUTION 才可以有多个limitDate */
  DATE_EXECUTION(1, "日期模式"),
  PERIODIC_EXECUTION(2, "周期模式");

  private final Integer value;
  private final String name;

  RealTimeMode(int value, String name) {
    this.name = name;
    this.value = value;
  }

  /**
   * @param value 编号
   * @return 对应的类型
   */
  public static RealTimeMode getRealTimeMode(Integer value) {
    Objects.requireNonNull(value, "AdjustMode can not be null.");
    return Arrays.stream(RealTimeMode.values())
        .filter(e -> e.value.equals(value))
        .findFirst()
        .orElseThrow(() ->  new ParameterException(ExceptionEnum.NOT_EXIST_ENUM));
  }

  @Override
  public Integer toProto() {
    return this.getValue();
  }

  @Override
  public RealTimeMode formProto(Integer integer) {
    return getRealTimeMode(integer);
  }
}
